#include <bits/stdc++.h>
using namespace std;

int dom[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

typedef long long ll;

int y, m, d, w;

ll t, ans;

inline bool run(int y) { 
  return ((y % 4 == 0 and y % 100 != 0) or y % 400 == 0);
}

int main() { 
  cin >> y >> m >> d >> t;
  int by = 1900, bm = 1, bd = 1, bw = 1;
  while (by != y or bm != m or bd != d) { 
    bw++;
    if (bw == 8) bw = 1;
    bd++;
    if (bd == dom[bm] + 1) 
      bd = 1, bm++;
    if (bm == 12 + 1) 
      bm = 1, by++;
    if (run(by)) 
      dom[2] = 29;
    else 
      dom[2] = 28;
  }
  w = bw;
  ll tt = min(t, 1ll * 146464);
  while (--t, --tt) { 
    if (bm == bd and bd == bw and bw == w) {
      ans++;
      cout << by << ' ' << bm << '\n';
    }
    bw++;
    if (bw == 8) bw = 1;
    bd++;
    if (bd == dom[bm] + 1) 
      bd = 1, bm++;
    if (bm == 12 + 1) 
      bm = 1, by++;
    if (run(by)) 
      dom[2] = 29;
    else 
      dom[2] = 28;
  }
  if (t / 146464) { 
    ans *= t / 146464;
    t %= 146464;
  }
  cout << ans;
  while (--t) { 
    if (bm == bd and bd == bw and bw == w) 
      ans++;
    bw++;
    if (bw == 8) bw = 1;
    bd++;
    if (bd == dom[bm] + 1) 
      bd = 1, bm++;
    if (bm == 12 + 1) 
      bm = 1, by++;
    if (run(by)) 
      dom[2] = 29;
    else 
      dom[2] = 28;
  }
}
